package me.abel.auditing.config;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Jpa 自定义审计功能 Registrar
 */
public class JpaAuditingHandlerRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        registry.registerBeanDefinition("customAuditingHandler", BeanDefinitionBuilder
                .rootBeanDefinition(CustomAuditingHandler.class)
                /**
                 * @see BeanDefinitionNames#JPA_MAPPING_CONTEXT_BEAN_NAME
                 */
                .addConstructorArgReference("jpaMappingContext")
                .getBeanDefinition());
    }
}